package com.tinem.platform.module.starter.jms.config;

import com.tinem.platform.module.starter.jms.consumer.ConsumerService;
import com.tinem.platform.module.starter.jms.consumer.impl.ActiveMqConsumerService;
import com.tinem.platform.module.starter.jms.util.JmsUtil;
import com.tinem.platform.module.starter.jms.util.impl.JmsQueuesUtil;
import com.tinem.platform.module.starter.jms.util.impl.JmsTopicUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jms.annotation.EnableJms;
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
import org.springframework.jms.config.JmsListenerContainerFactory;

import javax.jms.ConnectionFactory;

/**
 * @author fzh
 * @version v1
 * @program: platform
 * @className JmsConfiguration
 * @description
 * @site
 * @company
 * @create 2021-11-08 14:10
 */
@EnableJms
@Configuration
public class JmsConfiguration {

    @Bean
    @Primary
    JmsUtil jmsUtil(){
        return new JmsQueuesUtil();
    }

    @Bean
    JmsUtil jmsTopicUtil(){
        return new JmsTopicUtil();
    }

    @Bean
    ConsumerService consumerService(){
        return new ActiveMqConsumerService();
    }

    @Bean
    @Primary
    public JmsListenerContainerFactory<?> queueListenerFactory(ConnectionFactory connectionFactory) {
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
        factory.setPubSubDomain(false);
        factory.setConnectionFactory(connectionFactory);
        return factory;
    }
}
